export default {
  namespaced: true,
  //toastType (提示框得类型 success 成功  danger 错误  warning 警告)
  state: {
    //弹窗是否显示
    toastShow: false,
    //  弹窗类型
    toastType: "",
    // 提示内容
    toastMsg: "",
  },
  getters: {},
  mutations: {
    changeToastShow(state, payload) {
        //先判断传入的弹窗状态是true是再进行逻辑，防止定时器传入false的时候将弹窗类型和信息修改成空
      state.toastShow = payload.toastShow;
      if (payload.toastShow) {
        state.toastType = payload.toastType;
        state.toastMsg = payload.toastMsg;
      }
    },
  },
  actions: {
    // 打开提示框 ，异步关闭提示框
    asyncChangeToastShow({ commit }, payload) {
      commit("changeToastShow", {
        toastShow: true,
        toastType: payload.toastType,
        toastMsg: payload.toastMsg,
      });
      setTimeout(() => {
        commit("changeToastShow", {
          toastShow: false,
        });
      }, 1500);
    },
  },
};
